package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebInspectiondatarecordServiceImpl implements WebInspectiondatarecordService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebInspectiondatarecordServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebInspectiondatarecordMapper webInspectiondatarecordMapper;


    @Override
    public WebInspectiondatarecord create(WebInspectiondatarecord item) {

         webInspectiondatarecordMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webInspectiondatarecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebInspectiondatarecord item) {

        return webInspectiondatarecordMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebInspectiondatarecord get(Integer id) {
        return webInspectiondatarecordMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<WebInspectiondatarecord> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,WebInspectiondatarecord item){

        WebInspectiondatarecordExample  example = new WebInspectiondatarecordExample();
        WebInspectiondatarecordExample.Criteria criteria = example.createCriteria();
        if(item.getRecordid() != null ){
            criteria.andRecordidEqualTo(item.getRecordid());
        }
        if(item.getEquipmenttypekey() != null ){
            criteria.andEquipmenttypekeyEqualTo(item.getEquipmenttypekey());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if(item.getItemid() != null ){
            criteria.andItemidEqualTo(item.getItemid());
        }
        if(item.getItemvalue() != null ){
            criteria.andItemvalueEqualTo(item.getItemvalue());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebInspectiondatarecord> list = this.webInspectiondatarecordMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public WebInspectiondatarecord getBykey(String equipmenttypekey, String equipmentkey,Integer itemid) {
        return this.webInspectiondatarecordMapper.getByKey(equipmenttypekey, equipmentkey,itemid);
    }

    @Override
    public WebInspectiondatarecord getOneBykey(Integer recordid,String equipmenttypekey, String equipmentkey,Integer itemid) {
        return this.webInspectiondatarecordMapper.getOneByKey(recordid,equipmenttypekey, equipmentkey,itemid);
    }

    @Override
    public int batchInsert(List<WebInspectiondatarecord> list) {
        return this.webInspectiondatarecordMapper.batchInsert(list);
    }

    @Override
    public List<WebInspectiondatarecord> getList( Integer recordid) {

        List< WebInspectiondatarecord> list = this.webInspectiondatarecordMapper.gitList(recordid);
        return list;
    }


}
